package cs.ui250.carnatic;

import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import android.widget.ToggleButton;

public class FlashCardsSettingsDialog extends Dialog {

	Context mContext;

	ToggleButton mRBAToggle;
	ToggleButton mRBSToggle;
	ToggleButton mSBRToggle;

	public FlashCardsSettingsDialog(Context context) {
		super(context);
		mContext = context;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.settings_popup);
		setTitle("Question Settings");
		Button mCloseButton = (Button) findViewById(R.id.settings_close_button);
		mCloseButton.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				if (!mRBAToggle.isChecked() && !mRBSToggle.isChecked()
						&& !mSBRToggle.isChecked()) {
					Toast.makeText(mContext,
							"At least one option must be checked.", Toast.LENGTH_LONG)
							.show();
				} else {
					SharedPreferences values = PreferenceManager
							.getDefaultSharedPreferences(mContext);
					SharedPreferences.Editor editor = values.edit();
					editor.putBoolean("RBA", mRBAToggle.isChecked());
					editor.putBoolean("RBS", mRBSToggle.isChecked());
					editor.putBoolean("SBR", mSBRToggle.isChecked());
					editor.commit();
					dismiss();
				}
			}
		});
		mRBAToggle = (ToggleButton) findViewById(R.id.settings_toggle_by_audio);
		mRBSToggle = (ToggleButton) findViewById(R.id.settings_toggle_by_swara);
		mSBRToggle = (ToggleButton) findViewById(R.id.settings_toggle_by_raga);

		SharedPreferences values = PreferenceManager
				.getDefaultSharedPreferences(mContext);	
		mRBAToggle.setChecked(values.getBoolean("RBA", true));
		mRBSToggle.setChecked(values.getBoolean("RBS", true));
		mSBRToggle.setChecked(values.getBoolean("SBR", true));
	}

}
